package com.cykj.pos.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cykj.common.core.domain.entity.SysUser;
import com.cykj.pos.domain.*;

import com.cykj.pos.domain.dto.BizMercahntFeeNameDTO;
import com.cykj.pos.domain.dto.BizMerchantDTO;
import com.cykj.pos.domain.dto.BizTransactionCountDTO;
import com.cykj.pos.domain.posone.PosOneMerchantInfo;
import com.cykj.pos.domain.vo.BizGdbArea;
import com.cykj.pos.domain.vo.BizMerchParentRelated;
import com.cykj.pos.domain.vo.MerchantDetailDTO;
import com.cykj.pos.domain.vo.PartnerDetailDTO;
import com.cykj.pos.profit.dto.MerchantDTO;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 商户基本信息Mapper接口
 *
 * @author xuxiaolong
 * @date 2022-08-09
 */
public interface BizMerchantInfoMapper extends BaseMapper<BizMerchantInfo> {

    /**
     * 查询审核成功的报件
     * @return
     */
    List<BizMerchantInfo> selectMerchantInfoByAuditStatus();



    /***
     * 更新审核状态
     * @param bizMerchantInfo
     */
    int updateByMerchantCode(BizMerchantInfo bizMerchantInfo);

    void updateFeeIdByMerchantNo(@Param("merchantCode") String merchantCode,@Param("feeId") Long feeId);

    /**
     * 查询商户乐刷sn
     * @param merchantNo
     * @return
     */
    BizMerchantInfo getLeShuaSn(String merchantNo);

    void updateWhetherPhoto(String merchantNo);

    void updateWhethervideo(String merchantNo);

    /**
     * 查询posp我的商户
     * @param merchantDTO
     * @return
     */
    List<PosOneMerchantInfo> getPospMerchantInfo(MerchantDTO merchantDTO);

    void insertBizEntrySn(BizMerchantInfo bizMerchantInfo);

    /**
     * 回显商户基本信息
     * @param bizMerchantInfo
     * @return
     */
    BizMerchantInfo getMerchantInfo(BizMerchantInfo bizMerchantInfo);

    /**
     * 查询商户数量POSP
     * @param merchId
     * @return
     */
    int queryMyMerchNumPosP(Long merchId);

    /**
     * 回显费率模板
     * @return
     */
    List<BizMercahntFeeNameDTO> echoFeeId();

    /**
     * 回显商户信息
     * @param bizMerchantInfo
     * @return
     */
    BizMerchantDTO echoMerchantInfo(BizMerchantInfo bizMerchantInfo);

    /**
     * 修改进件信息
     * @param bizMerchantInfo
     */
    void updateMerchantsInfoByMerchantCode(BizMerchantInfo bizMerchantInfo);

    String selectMerchantInfoSn(String posCode);

    List<BizMerchantInfo> queryList(BizMerchantInfo bizMerchantInfo);

    /**
     * 更新绑定
     * @param merchantNo
     */
    void updateMercahntInfoWhetherBinding(@Param("merchantNo") String merchantNo,@Param("posCode") String posCode);

    /**
     * 根据sn和身份证号查询报件
     * @param bizMerchantInfo
     * @return
     */
    BizMerchantInfo selectMerchantInfoByCertificateNoAndSn(BizMerchantInfo bizMerchantInfo);

    /**
     * 根据id删除报件信息
     * @param id
     */
    void deleteMerchantInfoById(Integer id);


    @Select("select count(*) from biz_merchant_info where merch_id = #{merchId}")
    int selectNumPOSP(Long merchId);

    @Update("update biz_merchant_info set pos_code = #{posCode} where merchant_code = #{merchantNo}")
    void savePosCodeByNo(@Param("merchantNo")String merchantNo, @Param("posCode")String posCode);


    BizMerchantInfo selectMerchantInfoBySn(String snCode);

    @Select("SELECT var5 FROM biz_version_record where var3=#{suffix}")
    String getAgentId(String suffix);
    @Select("select suffix from sys_user where user_id=#{userId}")
    String getSuffix(Long userId);

    String getAgentRate(@Param("posCode") String posCode);

    String getDeptIdByPosCode(String posCode);

    String getMerchantInfoStatus(String posCode);

    @Select("select merchant_code from biz_back_merchant limit 100")
    List<String> selectBackMerchant();

    @Delete("delete from biz_back_merchant where merchant_code=#{merchantCode}")
    void deleteBackMerchant(String merchantCode);

    void updateMerchantFee(@Param("merchantCode")String merchantCode, @Param("feeId")Integer feeId);

    void updateSettleAccountStatusByMerchantCode(BizMerchantInfo bizMerchantInfo1);

    void updateSettleAccountStatus(String merchantCode);

    int updateSettleAccountByMerchantCode(BizMerchantInfo bizMerchantInfo);

    List<BizMerchantInfo>  getMerchantInfoRecord(String posCode);

    void updateSNByPosCode(String posCode);

    BizMerchantInfo getMerchantInfoBySn(String snCode);

    void updateWhetherStatus(BizMerchantInfo bizMerchantInfo);

    BizMerchantInfo getMerchantInfoByMerchantId(String merchantId);

    int transferPos1(BizMerchantInfo bizMerchantInfo);
    int transferPos2(BizMerchantInfo bizMerchantInfo);

    @Select("select p.pos_code as sn,p.terminal_no,p.merch_id from biz_merchant_info bmi left join biz_pos_machine p on  bmi.pos_code=p.pos_code where bmi.merchant_code=#{merchantNo}")
    List<BizTransactionCountDTO> selectBizMerchantInfoByMerchantNo(BizMerchantEntry bizMerchantEntry);

    @Select("select legal_person_name merchName,register_time activeTime,bank_card_account card,bmfn.fee_value fee from biz_merchant_info bmi left join biz_merchant_fee_name bmfn on bmi.fee_id=bmfn.fee_id where merchant_code =#{merchantNo}")
    BizTransactionCountDTO selectBizMerchantEntryMerchNameAndTime(String merchantNo);

    BizMerchantInfo getInfoByMerchantCode(String merchantCode);

    List<BizGdbArea> GDBProvince();

    List<BizGdbArea> GDBCity(BizGdbArea bizGdbArea);

    BizMerchantEpspBinding checkIsExists(String bankCardNo);

    @Select("select brd.nick_name from sys_user su LEFT JOIN biz_agent_open_account baoa ON baoa.account_id = su.account_id LEFT JOIN biz_rate_data brd ON brd.id = baoa.rateT0 where su.user_id=#{userId}")
    String getUserFl(Long userId);

    @Select("select * from biz_merchant_fee_name where fee_name>=#{userFl}")
    List<BizMercahntFeeNameDTO> getFeeId(String userFl);
    void updateKDBInfo(BizMerchantInfo bizMerchantInfo);
    void kdbBindCallback(BizMerchantInfo bizMerchantInfo);
    /**
     * 查询线上pos
     * @param merchantDTO
     * @return
     */
    List<PosOneMerchantInfo> online(MerchantDTO merchantDTO);
    @Select("select count(*) from biz_merchant_info where merch_id = #{merchId} and on_line='1'")
    int queryOnline(Long merchId);
    /**
     * 回显费率模板
     * @return
     */
    List<BizMercahntFeeNameDTO> echoFeeIdOnline();
    @Delete("delete from biz_merchant_info where pos_code=#{posSn}")
    void deleteBySN(String posSn);
    List<BizKdbIndustry> kdbIndustry();
    List<BizPosLsMcc> lsIndustry();
    @Insert("insert into biz_noback(sn) values(#{posCode})")
    int insertNoback(String posCode);
    BizPosLsMcc getlsIndustry(String mcc);

    List<BizWallet> getWalletList();

    String getYesterDayStatistics(@Param("merchId") Long merchId, @Param("yesterday")String yesterday, @Param("type")String type);

    List<BizMerchantInfo> getCupsNameList(String idCard);

    List<BizMerchantInfo> getMerchantInfoList(String idCard);

    BizMerchantInfo getMerchantInfoByMerchantCode(String oldMerchantCode);

    List<BizMerchantInfo> getNoSnMerchantInfo(String idCard);

    BizKdbBank getKdbBank(@Param("provinceName")String provinceName, @Param("cityName")String cityName, @Param("areaName")String areaName, @Param("bankName")String bankName);

    BizKdbBank getKdbBankEndCity(@Param("provinceName")String provinceName, @Param("cityName")String cityName, @Param("bankName")String bankName);

    BizKdbBank getKdbBankEndProvince(@Param("provinceName")String provinceName, @Param("bankName")String bankName);

    void insertTestForRule(String merchantCode);

    List<BizMerchantInfo> getPlUpdateFeeList();

    List<BizTransactionAmountEntity> selectTransData();

    List<SysUser> getUpdateRate();

    Long getMerchIdByUserId(Long userId);

    List<BizMerchParentRelated> getChildrensBuParentId(Long merchId);

    Long getUserIdByMerchId(Long childMerchId);

    void updateRateByUserId(@Param("userId")Long userId, @Param("rate")BigDecimal rate);

    List<BizMerchantInfo> getForFee();

    void updateFailFee(String merchantCode);

    List<BizMerchantInfo> getINfos();

    List<BizMerchantInfo> getFeeInfos();

    void updateSlienceRule(String merchantCode);

    List<BizMerchantInfo> getNewMerchantInfoList(BizMerchantInfo bizMerchantInfo);

    List<Long> getMerchParentRelated(Long merchId);

    List<Long> getMerchParentRelated2(@Param("merchId")Long merchId,@Param("pageNooo")int pageNooo,@Param("pageSizeee")int pageSizeee);

    MerchantDetailDTO getMerchantInfoDetailByMerchantCode(String merchantCode);

    PartnerDetailDTO getTeamTransAmount(@Param("merchTeamIds")List<Long> merchTeamIds);

    int getSnCountByMerchId(Long merchId);

    BizChannel getChannelDataByChannel(String channel);

    SysUser getSysUserByMerchId(Long merchId);


    List<BizMerchantInfo> selectAllMerchantInfo();

    void updateCustomerCashBackStatus(BizMerchantInfo info);

    List<BizMercahntFeeNameDTO> getDefaultFeeId();

    BizMerchantInfo getMerchantInfoBySnAndSuccess(String posCode);

    BizMerchantDTO echoMerchantInfoNewFee(BizMerchantInfo bizMerchantInfo);

    List<BizMercahntFeeNameDTO> echoFeeIds(Double minFeeRate);

    void insertNewChannel(BizChannel bizChannel);

    BizSms getSmsByDeptId(Long deptId);

    List<BizMerchantInfo> getSilentMerchantInfo(BizMerchantInfo bizMerchantInfo);

    List<BizMerchantInfo> getUnActiveMerchantInfo(BizMerchantInfo bizMerchantInfo);

    List<BizMerchantInfo> getFailureActiveMerchantInfo(BizMerchantInfo bizMerchantInfo);

    List<BizMerchantInfo> getMerchantInfos();

    void updateTransAmount(BizMerchantInfo info);

    void updateTransAmount1(BizMerchantInfo info);

    void updateCustomerCashBackTotalAmount(BizMerchantInfo info);

    List<BizMerchantInfo> getLsMerchantInfo();

    List<AllocationRelation> getAllocationRList(BizMerchantInfo bizMerchantInfo);
}
